<%@ page language="java" contentType="text/html; charset=GBK" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.Util" %>
<%
    JSONObject datas = new JSONObject();
    BaseBean baseBean = new BaseBean();
    String requestid = Util.null2String(request.getParameter("requestid"));
    int formid = Util.getIntValue(request.getParameter("formid"));
    formid = Math.abs(formid);
    String signlist = Util.null2String(request.getParameter("signlist"));
    baseBean.writeLog(">>>>>addSignLoca_Ajax.jsp>>>>>requestid=" + requestid);
    baseBean.writeLog(">>>>>addSignLoca_Ajax.jsp>>>>>formid=" + formid);
    baseBean.writeLog(">>>>>addSignLoca_Ajax.jsp>>>>>signlist=" + signlist);
    RecordSet rs = new RecordSet();
    try {
        JSONArray list = JSONArray.parseArray(signlist);
        baseBean.writeLog(">>>>>addSignLoca_Ajax.jsp>>>>>list=" + list);
        String mainid = getMainidById(formid, requestid);
        baseBean.writeLog(">>>>>addSignLoca_Ajax.jsp>>>>>mainid=" + mainid);
        rs.executeUpdate("delete formtable_main_" + formid + "_dt1 where mainid=?", mainid);
        String locations = Util.null2String(list.getJSONObject(0).getString("locations"));
        baseBean.writeLog(">>>>>addSignLoca_Ajax.jsp>>>>>locations=" + locations);
        JSONArray locationsList = JSONArray.parseArray(locations);
        baseBean.writeLog(">>>>>addSignLoca_Ajax.jsp>>>>>locationsList=" + locationsList);
        int counts = locationsList.size();
        int count = 0;
        for (int i = 0; i < locationsList.size(); i++) {
            String offsetX = locationsList.getJSONObject(i).getString("offsetX");
            String offsetY = locationsList.getJSONObject(i).getString("offsetY");
            String pages = locationsList.getJSONObject(i).getString("page");
            String sealId = locationsList.getJSONObject(i).getString("sealId");
            baseBean.writeLog(">>>>>addSignLoca_Ajax.jsp>>>>>offsetX=" + offsetX + ",offsetY=" + offsetY + ",pages=" + pages+",sealId="+sealId);
            String sql = "insert into formtable_main_" + formid + "_dt1 (mainid,xh,yzid,xz,yz,ym) values ('" + mainid + "','" + i + "','"+sealId+"','" + offsetX + "','" + offsetY + "','" + pages + "')";
            boolean flag = rs.executeUpdate(sql);
            if (flag) {
                count++;
            }
        }
        boolean status = false;
        if (counts > 0 && counts == count) {
            status = true;
        }
        datas.put("status", status);
    } catch (Exception e) {
        datas.put("status", false);
        e.printStackTrace();
    }
    out.print(datas.toJSONString());
%>
<%!
    public static String getMainidById(int formid, String requestid) {
        RecordSet rs = new RecordSet();
        rs.executeQuery("select id from formtable_main_" + formid + " where requestid=?", requestid);
        rs.next();
        return Util.null2String(rs.getString("id"));
    }
%>